package com.cpr.shop.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author CPR
 * @Create 2025/1/26 0:27
 * @Version 1.0
 * @Description 创建和修改时自动填充时间数据
 */
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("开始进行插入填充...【创建时间】【修改时间】...");
        this.strictInsertFill(metaObject, "createTime", Date::new, Date.class);
        this.strictInsertFill(metaObject, "updateTime", Date::new, Date.class);
//        strictInsertFill(metaObject, "delFlag", () -> 0, Integer.class);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("开始进行修改填充...【修改时间】...");
        this.strictInsertFill(metaObject, "updateTime", Date::new, Date.class);
    }
}
